"""
 -*- coding: utf-8-*-
 @File: page_add_member.py
 @Author: chen
 @time: 2023/10/04/ 20:29
"""
import time

import allure
from appium.webdriver.common.appiumby import AppiumBy
from appium.webdriver.common.mobileby import MobileBy

from hogwartsHomework.homework_app_auto_L3.dev.pages.page_base import BasePage
from hogwartsHomework.homework_app_auto_L3.utils.mgt_log import logger


class AddMemberPage(BasePage):
    def goto_add_member_by_hand(self):
        """点击手动添加按钮，进入手动添加成员页面"""
        button_add_by_hand = (AppiumBy.XPATH, '//*[@text="手动输入添加"]')
        with allure.step("点击手动输入添加按钮"):
            logger.info("点击手动输入添加按钮")
            # self.wait_until_clickable(button_add_by_hand)
            self.do_click(button_add_by_hand)
        from hogwartsHomework.homework_app_auto_L3.dev.pages.page_add_member_by_hand import AddMemberByHandPage
        logger.info("进入手动添加成员页面")
        return AddMemberByHandPage(self.driver)

    def back_to_contact_list(self):
        """点击返回按钮，回到通讯录页面"""
        button_back = (AppiumBy.ID, 'com.tencent.wework:id/lki')
        with allure.step("点击返回按钮"):
            logger.info("点击返回按钮")
            self.do_click(button_back)
        from hogwartsHomework.homework_app_auto_L3.dev.pages.page_contact_list import ContactListPage
        logger.info("进入通讯录页面")
        # time.sleep(5)
        return ContactListPage(self.driver)

    def get_toast(self):
        context_success = (MobileBy.XPATH, '//*[contains(@text,"成功")]')
        return self.do_find(context_success).text
